<template>
  <view class="modlist">
    <view class="tipss C999">
      保密后别人将无法查看到您
      <view>为了提高相亲成功率，建议全部开启</view>
    </view>
    <view class="ul">
      <view v-if="ARR.hidedata == '1'" class="li nogo" style="border-top: 24rpx #f5f5f5 solid">
        <text class="h4">个人资料显示</text>
        <switch :checked="ARR.cook_flag == 1" :color="color" @change="hidemyFn"></switch>
      </view>
      <view v-if="ARR.hidephoto == '1'" class="li nogo">
        <text class="h4">头像照片显示</text>
        <switch :checked="ARR.cook_photo_ifshow == '1'" :color="color" @change="hidephotoFn"></switch>
      </view>
    </view>
    <view class="ul">
      <view class="li" style="border-top: 24rpx #f5f5f5 solid">
        <button @tap="onContract">我的合同</button>
      </view>
      <view class="li" style="border-top: 24rpx #f5f5f5 solid">
        <button openType="openSetting">订阅消息通知</button>
      </view>
      <view class="li" style="border-top: 24rpx #f5f5f5 solid">
        <button @tap="delFn">注销当前帐号</button>
      </view>
    </view>
  </view>
</template>

<script>
require('../../res/www.a9a.cn.js');
var o;
var app = getApp();
export default {
  data() {
    return {
      color: '',

      ARR: {
        hidedata: '',
        cook_flag: 0,
        hidephoto: '',
        cook_photo_ifshow: ''
      }
    };
  },
  onLoad: function (t) {
    var that = this;
    app.globalData.chklogin().then(function (o) {
      o || uni.navigateBack();
    });
    app.globalData.get_openid().then(function (t) {
      that.setData({
        color: app.globalData._ZEAI.color
      });
      o = uni.getStorageSync('COOK_U');
      app.globalData.ajax({
        url: 'my_set.php',
        data: {
          submitok: 'init',
          openid: o.openid
        },
        success: function (o) {
          if (1 == o.flag) {
            that.setData({
              ARR: o.ARR
            });
          } else {
            uni.showModal({
              content: o.msg,
              confirmColor: that.color,
              confirmText: '朕知道了',
              showCancel: false,
              success: function (o) {
                uni.navigateBack();
              }
            });
          }
        }
      });
    });
  },
  methods: {
    hidemyFn: function (t) {
      var that = this;
      app.globalData.ajax({
        url: 'my_set.php',
        data: {
          submitok: 'flag',
          openid: o.openid
        },
        success: function (o) {
          if (1 == o.flag) {
            uni.showToast({
              title: o.msg,
              icon: 'none',
              mask: true
            });
          } else {
            uni.showModal({
              content: o.msg,
              confirmColor: that.color,
              confirmText: '朕知道了',
              showCancel: false,
              success: function (o) {
                uni.navigateBack();
              }
            });
          }
        }
      });
    },

    hidephotoFn: function (t) {
      var that = this;
      app.globalData.ajax({
        url: 'my_set.php',
        data: {
          submitok: 'photo_ifshow',
          openid: o.openid
        },
        success: function (o) {
          1 == o.flag
              ? uni.showToast({
                title: o.msg,
                icon: 'none',
                mask: true
              })
              : uni.showModal({
                content: o.msg,
                confirmColor: that.color,
                confirmText: '朕知道了',
                showCancel: false,
                success: function (o) {
                  uni.navigateBack();
                }
              });
        }
      });
    },
    onContract() {
      uni.navigateTo({
        url: '/myPages/myContract/myContract'
      });
    },
    delFn: function () {
      var that = this;
      uni.showModal({
        title: '',
        content: '确定要注销帐号么？\n注销后将不能登录使用本平台，请慎重！',
        confirmColor: that.color,
        cancelText: '取消',
        confirmText: '确定',
        success: function (a) {
          if (a.confirm) {
            app.globalData.ajax({
              url: 'my_set.php',
              data: {
                submitok: 'del',
                openid: o.openid
              },
              success: function (o) {
                1 == o.flag
                    ? (uni.showToast({
                      title: o.msg,
                      icon: 'none',
                      mask: true
                    }),
                        setTimeout(function () {
                          uni.reLaunch({
                            url: '/pages/index/index4'
                          });
                        }, 2000))
                    : uni.showModal({
                      content: o.msg,
                      confirmColor: that.color,
                      confirmText: '朕知道了',
                      showCancel: false,
                      success: function (o) {
                        uni.navigateBack();
                      }
                    });
              }
            });
          }
        }
      });
    }
  }
};
</script>
<style>
@import 'set.css';
</style>
